﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Dcms.Common;

public partial class Manage_Modle_Template_FileFolderEdit : System.Web.UI.Page
{
    protected string WebsitePath = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            MyDataBind();
        }
    }
    protected void MyDataBind()
    {
        WebsitePath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
        WebsitePath = WebsitePath.Replace('\\', '/');
        if (DcmsRequest.ValidaQueryStr("Action"))
        {
            HidAction.Value = Request.QueryString["Action"];
        }
        else
        {
            HidAction.Value = "Create";
        }

        if (DcmsRequest.ValidaQueryStr("Type"))
        {
            Hidtype.Value = Request.QueryString["Type"];
        }
        else
        {
            Hidtype.Value = "folder";
        }
        if (DcmsRequest.ValidaQueryStr("Path"))
        {
            HidPath.Value = WebsitePath + Request.QueryString["Path"];
            if (HidAction.Value == "Edit")
            {
                string fileName = Request.QueryString["Path"];
                if (fileName.LastIndexOf('/') > 0)
                {
                    HidBackPath.Value = fileName.Substring(0, fileName.LastIndexOf('/'));
                    FoleFolderName.Text = fileName.Substring(fileName.LastIndexOf('/') + 1, fileName.Length - fileName.LastIndexOf('/') - 1);
                }
                else
                {
                    FoleFolderName.Text = fileName;
                    HidBackPath.Value = "";
                }
            }
            else
            {
                HidBackPath.Value = Request.QueryString["Path"];
            }
        }
        else
        {
            HidPath.Value = WebsitePath;
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        string NewFileName = "", UrlStr = "";
        UrlStr ="FileList.aspx?Path="+HidBackPath.Value;
        try
        {
            if (HidAction.Value == "Edit")
            {
                NewFileName = HidPath.Value.Substring(0, HidPath.Value.LastIndexOf('/')) + "/" + FoleFolderName.Text;
                DcmsFileManagerProcessor.RenameFileFolder(HidPath.Value, NewFileName, Hidtype.Value);
            }
            else
            {
                NewFileName = HidPath.Value+"/" + FoleFolderName.Text;
                DcmsFileManagerProcessor.CreateFolder(NewFileName);
            }
            Response.Write("<script>top.msg_close_tmp_biyuan('" + UrlStr + "');</script>");
        }
        catch (Exception ex)
        {
            Jscript.Alert("重命或是新建目录出错");
            return;
        }
    }
}
